function getDatabase() {
     return openDatabaseSync("userLogin", "1.0", "UserStorageDatabase", 100000);
}


// At the start of the application, we can initialize the tables we need if they haven't been created yet
function initialize() {
    var db = getDatabase();
    db.transaction(
        function(tx) {
            // Create the settings table if it doesn't already exist
            // If the table exists, this is skipped
            tx.executeSql('CREATE TABLE IF NOT EXISTS users(name TEXT)');
      });
}


// This function is used to write a setting into the database
function addUser(name) {
   var db = getDatabase();
   var res = "";
   db.transaction(function(tx) {
        var rs = tx.executeSql('INSERT INTO users VALUES (?);', [name]);
              if (rs.rowsAffected > 0) {
                res = "OK";
                  console.log("OK");
              } else {
                res = "Error";
                  console.log("ERROR");
              }
        }
  );
  // The function returns “OK” if it was successful, or “Error” if it wasn't
  return res;
}

// This function is used to delete a Data from the database
function deleteUser(name) {
   var db = getDatabase();
   var res = "";
   db.transaction(function(tx) {
        var rs = tx.executeSql('DELETE FROM users WHERE name=?;', [name]);
              //console.log(rs.rowsAffected)
              if (rs.rowsAffected > 0) {
                res = "OK";
                  console.log("OK");
              } else {
                res = "Error";
                  console.log("ERROR");
              }
        }
  );
  // The function returns “OK” if it was successful, or “Error” if it wasn't
  return res;
}



function getUser(name) {
   var db = getDatabase();
   var res="";
   var stringVarName=new Array();

   db.transaction(function(tx){
     var rs = tx.executeSql('SELECT * FROM users WHERE name=?;', [name]);
     if (rs.rows.length > 0) {
         for(var  index=0; index<rs.rows.length; index++){
                 //RETRIEVE NaME
                res = rs.rows.item(index).what;
                stringVar[index]=res;
         }
     } else {
         res = "Unknown";
     }
  })
    return stringVarName;
}

//DAN
